package com.netflexitysolutions.amazonws.ec2.internal.operations;

import com.amazonaws.ec2.doc._2009_04_04.EmptyElementType;
import com.amazonaws.ec2.doc._2009_04_04.ResetImageAttributeResponseType;
import com.amazonaws.ec2.doc._2009_04_04.ResetImageAttributeType;
import com.netflexitysolutions.amazonws.ec2.EC2;
import com.netflexitysolutions.amazonws.ec2.ImageAttributeType;

public class ResetImageAttributeOperation extends SingleObjectOperationExecutor<ResetImageAttributeType, Boolean> {

	private ImageAttributeType attributeType;
	
	public ResetImageAttributeOperation(EC2 ec2, String imageId, ImageAttributeType attribute) {
		super(ec2, imageId);
		this.attributeType = attribute;
	}

	@Override
	protected Boolean call(ResetImageAttributeType request) {
		request.setImageId(objectId);
		switch (attributeType) {
		case LAUNCH_PERMISSION:
			request.setLaunchPermission(new EmptyElementType());
			break;
		
		//in case reseting attribute is not supported we return false
		default:
			return false;
		}
		
		ResetImageAttributeResponseType response = getEC2().getService().resetImageAttribute(request);
		
		return response.isReturn();
	}

}
